//商户控制层
app.controller('sellerController', function ($scope, $controller, sellerService) {

    $controller('baseController', {$scope: $scope});//继承

    //读取列表数据绑定到表单中  
    $scope.findAll = function () {
        sellerService.findAll().success(
            function (response) {
                $scope.list = response;
            }
        );
    }

    //分页
    $scope.findPage = function (page, rows) {
        sellerService.findPage(page, rows).success(
            function (response) {
                $scope.list = response.rows;
                $scope.paginationConf.totalItems = response.total;//更新总记录数
            }
        );
    }

    //查询实体
    $scope.findOne = function () {
        sellerService.findOne().success(
            function (response) {
                $scope.entity = response;
            }
        );
    }

    //保存
    $scope.save = function () {
        var serviceObject;//服务层对象
        serviceObject = sellerService.update($scope.entity); //修改
        serviceObject.success(
            function (response) {
                if (response.success) {
                    alert(response.message);
                    //重新查询
                    $scope.findOne();//重新加载
                } else {
                    alert(response.message);
                }
            }
        );
    }

    //保存用户注册信息
    $scope.add = function () {
        sellerService.add($scope.entity).success(function (response) {
            if (response.success) {
                //跳转到登录页面
                location.href = "/shoplogin.html";
            } else {
                alert(response.message);
            }
        })
    }


    //批量删除
    $scope.dele = function () {
        //获取选中的复选框
        sellerService.dele($scope.selectIds).success(
            function (response) {
                if (response.success) {
                    $scope.reloadList();//刷新列表
                    $scope.selectIds = [];
                }
            }
        );
    }

    $scope.searchEntity = {};//定义搜索对象

    //搜索
    $scope.search = function (page, rows) {
        sellerService.search(page, rows, $scope.searchEntity).success(
            function (response) {
                $scope.list = response.rows;
                $scope.paginationConf.totalItems = response.total;//更新总记录数
            }
        );
    }

    //读取当前登录人
    $scope.showLoginName = function () {
        sellerService.loginName().success(
            function (response) {
                $scope.loginName = response.loginName;
            })

    }

    $scope.saveMsg = function () {
        alert("保存成功")
    }

    $scope.pwdEntity = {}//定义密码对象
    $scope.updatePwd = function () {
        sellerService.updatePwd($scope.pwdEntity).success(
            function (response) {
                if (response.success) {
                    alert(response.message);
                    window.location.reload()
                }
                else {
                    alert(response.message);
                }
            })

    }
});	